package com.feihong.txgw.ui.activity.user;

import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.animation.Interpolator;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.adapter.base.BaseQuickAdapter;
import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.LocationSource;
import com.amap.api.maps.TextureMapView;
import com.amap.api.maps.UiSettings;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.MyLocationStyle;
import com.amap.api.maps.model.animation.Animation;
import com.amap.api.maps.model.animation.TranslateAnimation;
import com.amap.api.services.core.AMapException;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.core.PoiItem;
import com.amap.api.services.core.SuggestionCity;
import com.amap.api.services.geocoder.GeocodeResult;
import com.amap.api.services.geocoder.GeocodeSearch;
import com.amap.api.services.geocoder.RegeocodeQuery;
import com.amap.api.services.geocoder.RegeocodeResult;
import com.amap.api.services.poisearch.PoiResult;
import com.amap.api.services.poisearch.PoiSearch;
import com.feihong.txgw.R;
import com.feihong.txgw.adapter.delivery.DeliverySearchPoiDataReAdapter;
import com.feihong.txgw.message.DelvieryAdrSelectMessage;
import com.feihong.txgw.message.LoginMessage;
import com.feihong.txgw.model.bean.deliveryAdr.AdressSelectMapPoiInfoEntity;
import com.feihong.txgw.ui.activity.base.BaseActivity;
import com.feihong.txgw.ui.activity.kaika.KaikaManager;
import com.feihong.txgw.utils.ToastUtils;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import butterknife.BindView;

import static com.amap.api.services.geocoder.GeocodeSearch.AMAP;
import static com.feihong.txgw.ui.activity.user.AdrSearchActivity.MAP_POI_SEARCH_INFO_KEY;
import static com.feihong.txgw.ui.activity.user.LocationActivty.DEFAULT_CITY_SHOW;
import static com.feihong.txgw.ui.activity.user.LocationActivty.FROM_WHERE_KEY;
import static com.feihong.txgw.utils.ScreenUtil.dip2px;

/**
 * @author wangziheng
 * @name txgw_app
 * @class name：com.feihong.txgw.ui.activity.user
 * @class describe:
 * @time 2018/3/7 19:20
 * @change
 * @chang time
 * @class describe
 */
public class MapAddressActivity extends BaseActivity implements
        AMap.OnMapClickListener, GeocodeSearch.OnGeocodeSearchListener,
        AMap.OnCameraChangeListener,
        PoiSearch.OnPoiSearchListener,
        LocationSource,
        View.OnClickListener,BaseQuickAdapter.RequestLoadMoreListener {

    public static final String MAP_POINT = "MAP_POINT";
    @BindView(R.id.adr_map) TextureMapView mMapView;
    /**
     * 当前定位的地址名称
     */
    @BindView(R.id.map_adr_poi_search_layout) LinearLayout chooseMerchantAddrLayout;
    @BindView(R.id.connect_net_error_half_layout) RelativeLayout mConnectErrorLayout;
    @BindView(R.id.re_query_data_half_layout) LinearLayout mReConnectLayout;
    @BindView(R.id.lay_loading) RelativeLayout mLoadLayout;
    @BindView(R.id.map_adr_poi_recyclerView_layout) RecyclerView mRecyclerView;
    @BindView(R.id.map_adr_poi_location) TextView mSlecetLocationTextView;
    private AMap aMap;
    /**
     * 地理编码
     */
    private GeocodeSearch geocoderSearch;
    /**
     * 声明AMapLocationClient类对象
     */
    private AMapLocationClient mLocationClient = null;
    /**
     * 声明AMapLocationClientOption对象
     */
    private AMapLocationClientOption mLocationOption = null;
    /**
     * 添加Marker显示定位位置
     */
    private Marker locationMarker = null;
    private LinearLayoutManager mLinearLayoutManager;
    private LatLng mLatLng;

    /**
     * poi返回的结果
     */
    private PoiResult poiResult;
    /**
     * poi数据
     */
    private List<PoiItem> poiItems;
    /**
     * 附近商圈 当前页面，从0开始计数
     */
    private int currentPage = 1;
    /**
     * Poi查询条件类
     */
    private PoiSearch.Query query;
    private PoiSearch poiSearch;

    /**
     * 定位是否发生错误
     */
    private boolean isLocationError = false;

    /**
     * 如果定位发生错误 则需要手动定位
     */
    private boolean isNeedSelectCity = false;
    /**
     * 当前列表是否有数据
     */
    private boolean isHasData;
    private MyLocationStyle myLocationStyle;

    private String mCityCode;

    private DeliverySearchPoiDataReAdapter mReAdapter;
    /**
     * 声明定位回调监听器
     */
    private AMapLocationListener mLocationListener = new AMapLocationListener() {
        @Override
        public void onLocationChanged(AMapLocation aMapLocation) {
            if (aMapLocation != null) {
                if (aMapLocation.getErrorCode() == 0) {
                    isLocationError = false;
                    isNeedSelectCity = false;
                    mCityCode = aMapLocation.getCityCode();
                    //取出经纬度
                    mLatLng = new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude());
                    moveCamera(mLatLng);
                } else {
                    isNeedSelectCity = true;
                    isLocationError = true;
                    mSlecetLocationTextView.setText("请选择城市");
                    if (aMapLocation.getErrorCode() == 12) {
                        mLoadLayout.setVisibility(View.GONE);
                        mConnectErrorLayout.setVisibility(View.VISIBLE);
                        ToastUtils.getInstance().showShortToast("没有定位权限 ");
                    } else if (aMapLocation.getErrorCode() == 10) {
                        mLoadLayout.setVisibility(View.GONE);
                        mConnectErrorLayout.setVisibility(View.VISIBLE);
                        ToastUtils.getInstance().showShortToast("请开启定位服务 ");
                    } else if (aMapLocation.getErrorCode() == 13) {

                        mLoadLayout.setVisibility(View.GONE);
                        mConnectErrorLayout.setVisibility(View.VISIBLE);
                        ToastUtils.getInstance().showShortToast("定位失败 ");
                    } else if (aMapLocation.getErrorCode() == 4) {
                        mLoadLayout.setVisibility(View.GONE);
                        mConnectErrorLayout.setVisibility(View.VISIBLE);
                        ToastUtils.getInstance().showShortToast("检查网络  ");
                    } else {
                        mLoadLayout.setVisibility(View.GONE);
                        mConnectErrorLayout.setVisibility(View.VISIBLE);
                        ToastUtils.getInstance().showShortToast("定位失败,请手动选择城市");
                    }
                    //定位失败时，可通过ErrCode（错误码）信息来确定失败的原因，errInfo是错误信息，详见错误码表。
                    if (aMapLocation.getErrorCode() == 12) {
                        mLoadLayout.setVisibility(View.GONE);
                        mConnectErrorLayout.setVisibility(View.VISIBLE);
                        ToastUtils.getInstance().showShortToast("缺少定位权限  ");
                    } else {
                        mLoadLayout.setVisibility(View.GONE);
                        mConnectErrorLayout.setVisibility(View.VISIBLE);
                        System.out.println(String.format("location Error, ErrCode:%s, errInfo:%s", aMapLocation.getErrorCode(), aMapLocation.getErrorInfo()));
                    }
                }
            }
        }
    };

    private final static int SELECT_ADR_MAP_KEY = 10;

    @Override
    public void setTheme() {

    }

    @Override
    public int setLayoutID() {
        return R.layout.activity_map_adrlayout;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        getMap(savedInstanceState);
        KaikaManager.getmKaikaManager().addStack(this);
        chooseMerchantAddrLayout.setOnClickListener(this);
        mSlecetLocationTextView.setOnClickListener(this);
        mLoadLayout.setVisibility(View.VISIBLE);
        mLinearLayoutManager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(mLinearLayoutManager);

        setPageTitle("选择地址");
        setBackButtonFinish();
        mPoiEntity = new AdressSelectMapPoiInfoEntity();
    }

    @Override
    public void bindData() {
        mReConnectLayout.setOnClickListener(this);
        mReAdapter = new DeliverySearchPoiDataReAdapter(R.layout.delivery_search_poi_item_layout);
        mReAdapter.setOnLoadMoreListener(this,mRecyclerView);
        mReAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                PoiItem poiItem = (PoiItem) adapter.getItem(position);
                DelvieryAdrSelectMessage delvieryAdrSelectMessage = new DelvieryAdrSelectMessage();
                delvieryAdrSelectMessage.setPoiItem(poiItem);
                EventBus.getDefault().post(delvieryAdrSelectMessage);
                KaikaManager.getmKaikaManager().clearAll();
            }
        });
        mRecyclerView.setAdapter(mReAdapter);
        getLocation();
        getGeocode();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //在activity执行onDestroy时执行mMapView.onDestroy()，销毁地图
        if(mMapView != null){
            mMapView.onDestroy();
        }
        //销毁定位客户端，同时销毁本地定位服务
        if (mLocationClient != null) {
            mLocationClient.onDestroy();
        }
    }

    private AdressSelectMapPoiInfoEntity mPoiEntity;

    @Override
    protected void onResume() {
        super.onResume();
        mMapView.onResume();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        //在activity执行onSaveInstanceState时执行mMapView.onSaveInstanceState (outState)，保存地图当前的状态
        mMapView.onSaveInstanceState(outState);
    }

    @Override
    protected void onPause() {
        super.onPause();
        //在activity执行onPause时执行mMapView.onPause ()，暂停地图的绘制
        mMapView.onPause();
        //停止定位后，本地定位服务并不会被销毁
        if (mLocationClient != null) {
            mLocationClient.onDestroy();
        }
    }

    @Override
    public void onUserLogin(LoginMessage loginMessage) {

    }

    @Override
    public void onCameraChange(CameraPosition cameraPosition) {

    }

    @Override
    public void onCameraChangeFinish(CameraPosition cameraPosition) {
        paintMark(new LatLng(cameraPosition.target.latitude, cameraPosition.target.longitude));
    }

    private void paintMark(LatLng point) {
        //添加Marker显示定位位置
        if (locationMarker == null) {
            //如果是空的添加一个新的,icon方法就是设置定位图标，可以自定义
//             自定义图标.
//                     icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(),R.mipmap.mark_r)));
            locationMarker = aMap.addMarker(new MarkerOptions().position(point).setFlat(true));
            //固定标签在屏幕中央
            locationMarker.setIcon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.location_icon)));
            locationMarker.setPositionByPixels(mMapView.getWidth() / 2, mMapView.getHeight() / 2);
        } else {
            //已经添加过了，修改位置即可
            locationMarker.setPosition(point);
            locationMarker.setPositionByPixels(mMapView.getWidth() / 2, mMapView.getHeight() / 2);
        }

        // 第一个参数表示一个Latlng，第二参数表示范围多少米，第三个参数表示是火系坐标系还是GPS原生坐标系
        geocoderSearch.getFromLocationAsyn(new RegeocodeQuery(new LatLonPoint(point.latitude, point.longitude), 200, AMAP));

        startJumpAnimation();
    }

    /**
     * 屏幕中心marker 跳动
     */
    public void startJumpAnimation() {

        if (locationMarker != null) {
            //根据屏幕距离计算需要移动的目标点
            final LatLng latLng = locationMarker.getPosition();
            Point point = aMap.getProjection().toScreenLocation(latLng);
            point.y -= dip2px(this, 60);
            LatLng target = aMap.getProjection()
                    .fromScreenLocation(point);
            //使用TranslateAnimation,填写一个需要移动的目标点
            Animation animation = new TranslateAnimation(target);
            animation.setInterpolator(new Interpolator() {
                @Override
                public float getInterpolation(float input) {
                    // 模拟重加速度的interpolator
                    if (input <= 0.5) {
                        return (float) (0.5f - 2 * (0.5 - input) * (0.5 - input));
                    } else {
                        return (float) (0.5f - Math.sqrt((input - 0.5f) * (1.5f - input)));
                    }
                }
            });
            //整个移动所需要的时间
            animation.setDuration(600);
            //设置动画
            locationMarker.setAnimation(animation);
            //开始动画
            locationMarker.startAnimation();

        } else {
            Log.e("amap", "screenMarker is null");
        }
    }

    @Override
    public void onMapClick(LatLng latLng) {
        moveCamera(latLng);
    }

    private UiSettings mUiSettings;

    /**
     * 开始进行poi搜索
     */
    public final static String MAP_POI_TYPE = "汽车服务|汽车销售|汽车维修|餐饮服务|购物服务|体育休闲服务|医疗保健服务|住宿服务|风景名胜|政府机构及社会团体|科教文化服务|金融保险服务|公司企业|地名地址信息|商务住宅|摩托车服务|生活服务|道路附属设施|交通设施服务";

    protected void doSearchQuery() {
        // 第一个参数表示搜索字符串，第二个参数表示poi搜索类型，第三个参数表示poi搜索区域（空字符串代表全国）
        query = new PoiSearch.Query("", MAP_POI_TYPE, mCityCode);
        // 设置每页最多返回多少条poiitem
        query.setPageSize(20);
        // 设置查看页数
        query.setPageNum(currentPage);
        if (mLatLng != null) {
            poiSearch = new PoiSearch(this, query);
            poiSearch.setOnPoiSearchListener(this);
            poiSearch.setBound(new PoiSearch.SearchBound(new LatLonPoint(mLatLng.latitude, mLatLng.longitude), 500, true));
            // 设置搜索区域为以lp点为圆心，其周围5000米范围
            poiSearch.searchPOIAsyn();// 异步搜索
        }
    }

    /**
     * 获取地图控件实例
     */
    private void getMap(Bundle savedInstanceState) {
        //在activity执行onCreate时执行mMapView.onCreate(savedInstanceState)，创建地图
        mMapView.onCreate(savedInstanceState);
        if (aMap == null) {
            // 地图对象
            aMap = mMapView.getMap();

            // 对amap添加单击地图事件监听器
            aMap.setOnMapClickListener(this);
            // 对amap添加移动地图事件监听器
            aMap.setOnCameraChangeListener(this);
        }
        mUiSettings = aMap.getUiSettings();
        mUiSettings.setZoomControlsEnabled(false);

        mUiSettings.setRotateGesturesEnabled(false);
        // 设置定位监听
        aMap.setLocationSource(this);
        // 设置默认定位按钮是否显示
        mUiSettings.setMyLocationButtonEnabled(true);
        // 设置为true表示显示定位层并可触发定位，false表示隐藏定位层并不可触发定位，默认是false
        aMap.setMyLocationEnabled(true);

//        // 设置定位的类型为定位模式 ，可以由定位、跟随或地图根据面向方向旋转几种

        myLocationStyle = new MyLocationStyle();
        aMap.setMyLocationStyle(myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_SHOW));
    }

    /**
     * 当前mark点位置名称
     *
     * @param regeocodeResult
     * @param rCode
     */
    @Override
    public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int rCode) {
        if (activityIsDestory()) {
            return;
        }
        mLoadLayout.setVisibility(View.GONE);
        if (rCode == 1000) {
            if (regeocodeResult != null && regeocodeResult.getRegeocodeAddress() != null && regeocodeResult.getRegeocodeAddress().getFormatAddress() != null) {
                currentPage = 1;
                LatLonPoint latLonPoint = regeocodeResult.getRegeocodeQuery().getPoint();
                mLatLng = new LatLng(latLonPoint.getLatitude(), latLonPoint.getLongitude());
                doSearchQuery();
            }
        } else if (!isHasData) {
                mConnectErrorLayout.setVisibility(View.VISIBLE);
                mRecyclerView.setVisibility(View.GONE);
         }
    }

    @Override
    public void onGeocodeSearched(GeocodeResult geocodeResult, int i) {

    }

    private void moveCamera(LatLng point) {
        //然后可以移动到定位点,使用animateCamera就有动画效果
        //参数提示:1.经纬度 2.缩放级别
        aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(point, 18));
    }

    private void getGeocode() {
        //地理编码事件监听
        geocoderSearch = new GeocodeSearch(this);
        geocoderSearch.setOnGeocodeSearchListener(this);
    }

    public void getLocation() {
        //初始化定位
        mLocationClient = new AMapLocationClient(getApplicationContext());
        //初始化AMapLocationClientOption对象
        mLocationOption = new AMapLocationClientOption();
        //设置定位回调监听
        mLocationClient.setLocationListener(mLocationListener);
        //设置定位模式为AMapLocationMode.Hight_Accuracy，高精度模式。
        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        //获取一次定位结果：
        mLocationOption.setOnceLocation(true);
        //给定位客户端对象设置定位参数
        mLocationClient.setLocationOption(mLocationOption);
        //启动定位
        mLocationClient.startLocation();
    }

    private String selectCity;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data == null) {
            return;
        }
        switch (requestCode) {
            case SELECT_ADR_MAP_KEY:
                String city = data.getStringExtra("city");
                selectCity = city;
                if (!TextUtils.isEmpty(city)) {

                    isNeedSelectCity = false;
                    if (city.length() > 4) {
                        city = city.substring(0, 4) + "..";
                    }
                    mSlecetLocationTextView.setText(city);
                    mPoiEntity.setCity(data.getStringExtra("city"));
                    mPoiEntity.setCityCode(data.getStringExtra("CityCode"));
                    mPoiEntity.setLatitude(data.getStringExtra("Latitude"));
                    mPoiEntity.setLongitude(data.getStringExtra("Longitude"));
                }
                break;
            default:
                break;
//            case MERCHANT_SEARCH_CODE:
//                MerchantSearchResultEntity merchantSearchResultEntity = (MerchantSearchResultEntity) data.getSerializableExtra("searchResult");
//                moveCamera(new LatLng(Double.parseDouble(merchantSearchResultEntity.getLat()),Double.parseDouble(merchantSearchResultEntity.getLng())));
//                break;
        }
    }

    @Override
    public void onPoiSearched(PoiResult result, int rcode) {
        if (activityIsDestory()) {
            return;
        }
        try {
            mLoadLayout.setVisibility(View.GONE);
            if (rcode == AMapException.CODE_AMAP_SUCCESS) {
                // 搜索poi的结果
                if (result != null && result.getQuery() != null) {
                    // 是否是同一条
                    if (result.getQuery().equals(query)) {
                        poiResult = result;
                        // 取得第一页的poiitem数据，页数从数字0开始
                        poiItems = poiResult.getPois();
                        // 当搜索不到poiitem数据时，会返回含有搜索关键字的城市信息
//                    List<SuggestionCity> suggestionCities = poiResult
//                            .getSearchSuggestionCitys();
                        String lon;
                        String lat;
                        PoiItem poiItem;
                        if (poiItems != null && poiItems.size() > 0) {
//                        StringBuilder stringBuilder = new StringBuilder();
//                        for(PoiItem poiItema : poiItems){
//                            String str = JSON.toJSONString(poiItems);
//                            stringBuilder.append("toString:"+poiItema.toString()+"  getDirection:"+poiItema.getDirection()+" getCityName:"+poiItema.getCityName()+" getAdName:"
//                            +poiItema.getAdName()+" getBusinessArea:"+poiItema.getBusinessArea()+" getDirection:"+poiItema.getDirection()+" getParkingType:"+poiItema.getParkingType()+" getSnippet:"+poiItema.getSnippet()
//                                    +" getTypeDes:"+poiItema.getTypeDes()+" getFloorName:"+poiItema.getIndoorData().getFloorName()+" getFloor:"+poiItema.getIndoorData().getFloor()+"  "+"\n"  );
//                        }

                            poiItem = poiItems.get(0);
                            selectCity = poiItem.getCityName();
                            mSlecetLocationTextView.setText(selectCity);
                            lon = String.valueOf(poiItem.getLatLonPoint().getLongitude());
                            lat = String.valueOf(poiItem.getLatLonPoint().getLatitude());
                            Log.i(TAG, "onPoiSearched: " + lon + "  " + lat);
                            mPoiEntity.setLongitude(lon);
                            mPoiEntity.setLatitude(lat);
                            mPoiEntity.setCityCode(poiItem.getCityCode());
                            mPoiEntity.setCity(selectCity);
                            if(currentPage > 1){
                                mReAdapter.addData(poiItems);
                            }else {
                                mReAdapter.setNewData(poiItems);
                                mRecyclerView.setVisibility(View.VISIBLE);
                                mConnectErrorLayout.setVisibility(View.GONE);
                            }
                            isHasData = true;
                            currentPage++;
                            mReAdapter.loadMoreComplete();

                        } else {
                            if(currentPage > 1){
                                mReAdapter.loadMoreEnd();
                            }else {
                                ToastUtils.getInstance().showShortToast(
                                        "没有搜索到相关数据");
                            }
                        }
                    }
                } else {
                    if (!isHasData) {
                        ToastUtils.getInstance().showShortToast(
                                "没有搜索到相关数据");
                    }
                    mReAdapter.loadMoreEnd();
                }
            } else {
                mReAdapter.loadMoreEnd();
                if (!isHasData) {
                    mRecyclerView.setVisibility(View.GONE);
                    mConnectErrorLayout.setVisibility(View.VISIBLE);
                }
            }
        } catch (Exception e) {
            if (!isHasData) {
                ToastUtils.getInstance().showShortToast(
                        "没有搜索到相关数据");
            }
            mReAdapter.loadMoreEnd(true);
        }
    }

    @Override
    public void onPoiItemSearched(PoiItem poiItem, int i) {

    }

    /**
     * poi没有搜索到数据，返回一些推荐城市的信息
     */
    private void showSuggestCity(List<SuggestionCity> cities) {
        String infomation = "推荐城市\n";
        for (int i = 0; i < cities.size(); i++) {
            infomation += "城市名称:" + cities.get(i).getCityName() + "城市区号:"
                    + cities.get(i).getCityCode() + "城市编码:"
                    + cities.get(i).getAdCode() + "\n";
        }
        ToastUtils.getInstance().showShortToast(infomation);
    }

    @Override
    public void activate(OnLocationChangedListener onLocationChangedListener) {
        if (mLocationClient == null) {
            getLocation();
        } else {
            mLocationClient.startLocation();
        }
    }

    /**
     * 停止定位
     */
    @Override
    public void deactivate() {
        mLocationListener = null;
        if (mLocationClient != null) {
            mLocationClient.stopLocation();
            mLocationClient.onDestroy();
        }
        mLocationClient = null;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.map_adr_poi_search_layout:
                if (isNeedSelectCity) {
                    ToastUtils.getInstance().showShortToast("请先选择城市");
                } else {
                    Intent intentAdr = new Intent(MapAddressActivity.this, AdrSearchActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putParcelable(MAP_POI_SEARCH_INFO_KEY, mPoiEntity);
                    intentAdr.putExtras(bundle);
                    startActivity(intentAdr);
                }
                break;
            case R.id.map_adr_poi_location:
                Intent intentLocation = new Intent(MapAddressActivity.this, LocationActivty.class);
                intentLocation.putExtra(FROM_WHERE_KEY, MapAddressActivity.class.getName());
                intentLocation.putExtra(DEFAULT_CITY_SHOW, selectCity);
                startActivityForResult(intentLocation, SELECT_ADR_MAP_KEY);
                getActivity().overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
                break;
            case R.id.re_query_data_half_layout:
                mConnectErrorLayout.setVisibility(View.GONE);
                mLoadLayout.setVisibility(View.VISIBLE);
                if (isLocationError) {
                    getLocation();
                } else {
                    doSearchQuery();
                }
                break;
            default:
                break;
        }
    }

    @Override
    public void onLoadMoreRequested() {
        doSearchQuery();
    }
}
